<template>
	<view>
		<!-- 分类选择 -->
		<view class="cate-container">
			<!-- 左侧 -->
			<scroll-view scroll-y="true" :style="{height: wh+'px'}" class="cate-left">

				<view v-for="(item,i) in cateList" :key="i" :class="['cate-left-item ',i===active?'active':'']"
					@click="changeActive(i)">{{item.cat_name}}</view>

			</scroll-view>
			<!-- 右侧 -->
			<scroll-view scroll-y=" true" class="cate-right" :style="{height: wh+'px'}" :scroll-top="scrollTop">
				<!-- 二级分类item -->
				<view class="cate-right-item" v-for="(item,i) in cateList2 " :key="i">
					<!-- 二级分类title -->
					<view class="cate-right-item-title">/{{item.cat_name}}/</view>
					<!-- 二级分类内容 -->
					<view class="cate-right-item-content">
						     <view class="cate-right-item-content-box" v-for="(item2, i2) in item.children" :key="i2"   @click="gotoGoodsList(item2)">
						        <!-- 二级分类图片 -->
						        <image :src="item2.cat_icon" mode="widthFix"></image>
						        <!-- 二级分类名称 -->
						        <text>{{item2.cat_name}}</text>
						      </view>

					</view>
				</view>

			</scroll-view>


		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				wh: 0,
				brand: '',
				cateList: [],
				active: 0,
				cateList2: [],
				cateList3:[],
				  scrollTop: 0
			};
		},
		onLoad() {
			const sysinfo = uni.getSystemInfoSync()
			console.log('高度', sysinfo)
			this.wh = sysinfo.windowHeight
			this.getCateList()

		},
		methods: {
			async getCateList() {
				const {
					data: res
				} = await uni.$http.get('/categories')
				if (res.meta.status !== 200) return uni.$showMsg()
				console.log('cateList', res)
				this.cateList = res.message
				this.cateList2 = this.cateList[0].children
			

			},
			changeActive(i) {
				this.active = i
				this.cateList2 = this.cateList[i].children
				this.scrollTop=this.scrollTop===0?1:0
			
			},
			gotoGoodsList(item){
				uni.navigateTo({
					url:`/subpkg/goods_list/goods_list?cid=${item.cat_id}`
				})
			}
		}
	}
</script>

<style lang="scss">
	.cate-container {
		display: flex;

		.cate-left {
			width: 240rpx;

			.cate-left-item {
				display: flex;
				justify-content: center;
				align-items: center;
				height: 120rpx;
				background-color: #efefef;
				font-size: 24rpx;

				// 选中样式
				&.active {
					display: flex;
					justify-content: space-between;
					background-color: #ffffff;

					// 左边红线
					&::before {
						content: '';
						width: 6rpx;
						height: 60rpx;
						background-color: #c00000;
					}

					// 右边白线和背景相同
					&::after {
						content: '';
						width: 6rpx;
						height: 60rpx;
						background-color: #fffff;
					}
				}
			}
		}
	}

	.cate-right {
	  .cate-right-item {
	    .cate-right-item-title{
	      display: flex;
	      justify-content: center;
	      font-weight: bold;
	      font-size: 24rpx;
	      padding: 20rpx 0;
	    }
	    .cate-right-item-content {
	      display: flex;
	      flex-wrap: wrap;
	      .cate-right-item-content-box {
	        display: flex;
	        flex-direction: column;
	        justify-content: center;
	        align-items: center;
	        width: 33.33%;
	        padding: 20rpx;
	        box-sizing: border-box;
	        image {
	          width: 100%;
	        }
	        text {
	          font-size: 24rpx;
	        }
	      }
	    }
	  }
	}
</style>
